<%@page import="java.text.SimpleDateFormat"%>
<%@page import="org.beanstech.dao.UserDao"%>
<%@page import="org.beanstech.dao.ObjectsByIds"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="org.beanstech.dao.BookDao"%>
<%@page import="com.ckeditor.CKEditorConfig"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.beanstech.model.SystemModel"%>
<%@page import="org.beanstech.persistence.Mstblsubject"%>
<%@page import="java.util.List"%>
<%@page import="org.beanstech.dao.DropDownConstructDao"%>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>
<%
	if(session.getAttribute("userid")==null){
	%>
	<jsp:forward page="Before_login.jsp"></jsp:forward>
	<%} %>

<%@include file="header.jsp" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="js/jquery.numeric.js"></script>
	<script type="text/javascript" src="js/jquery.fancybox.js?v=2.0.6"></script>
	<link rel="stylesheet" type="text/css" href="css/jquery.fancybox.css?v=2.0.6" media="screen" />
	
	<link rel="stylesheet" href="css/main.css" type="text/css" />
	<script type="text/javascript">
	function loginsubmit(){
		document.getElementById("sellbook").submit();
		
	}
	
	
	 $(document).ready(function() {
	        $('.toggle').hide();
	        $('.fancybox').fancybox({
	        	closeClick : true
	        });
	        $('.toggler').click( function() {
	          var target = this.id + '_content';
	          // Use ID-selectors to toggle a single element.
	          $('#' + target).toggle();
	          // Use class-selectors to toggle groups of elements.
	          $('.' + target).toggle();
	          $('.toggle.always').toggle();
	        });
	        $('#toggle_everything').click( function() { $('.toggle').toggle(); });
	    });
	 
	 function openPopup(userid,bookid){
		 window.open ('ShowContact.jsp?userid='+userid+'&bookid='+bookid,'mywindow','menubar=0,resizable=0,width=315,height=280');
	 }
</script>
	
	<title>Second Book Exchange | Effort towards Green Campaign</title>
	
	<%
	int cnt = 0;
	DropDownConstructDao dropdown = new DropDownConstructDao();
	List<SystemModel> customlist = dropdown.getSubjectList();
	CKEditorConfig settings = new CKEditorConfig();
	settings.addConfigValue("toolbar","[]");
	settings.addConfigValue("width","320");
	settings.addConfigValue("height","100");
	ObjectsByIds getID = new ObjectsByIds();
	SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy"); 
	BookDao doa = new BookDao();
	ResultSet rs = doa.BookSearch(request.getParameter("bookname"),request.getParameter("author"),(request.getParameter("subject")!=null?Integer.parseInt(request.getParameter("subject")):0));
	
	%>
</head><body>
		<div id="full_div_text">
		<div class="mydiv">
 		<h2>Listing of the search<br /> details</h2>
 		</div>
		<div class="mydiv">
		The results of the search according to our database<br/> and your search criteria  </div>
		<div class="mydiv">
		<table align="center" cellpadding="3px" cellspacing="5px" width="400px">
		
		<%while(rs.next()){ 
		if(cnt == 0){
		%>
		
		<tr >
		<td width="60px" >&nbsp;</td>
		<td width="290px">&nbsp; </td>
		<td width="50px">&nbsp;</td>
		</tr>
		<%}cnt++; %>
		<tr>
		<td align="center">
			<%if(rs.getString("bookimage")== null){ %>
							<img src="bookimg/default.png" height="60px" width="50px"/ title="<%=rs.getString("note").length()>100?rs.getString("note").substring(0,98)+"...":rs.getString("note") %>">
						<%}else { %>
							<img src="bookimg/<%=rs.getString("bookimage")%>" height="60px" width="50px" title="<%=rs.getString("note").length()>100?rs.getString("note").substring(0,98)+"...":rs.getString("note") %>"/ >
						<%} %>
		</td>
		<td><b><%=rs.getString("bookname") %></b>
		</td>
		 <td><span class="yellowrupee">`</span><%=rs.getString("offerprice") %></td>
		 </tr>
		 <tr>
		 <td>&nbsp;</td>
		 <td>  <%=rs.getString("author") %></td>
		  <td><a href="javascript:void(0)" class="toggler" id="toggle<%=rs.getInt("transbookid")%>" style="border: 1px solid; padding: 3px;">View</a></td>
		</tr>
		<tr class="toggle" id="toggle<%=rs.getInt("transbookid")%>_content">
			<td colspan="3">
				<table width="100%" cellpadding="0" cellspacing="0" >
					<tr>
						<td colspan="2"><hr /></td>
					</tr>
					<tr>
						<td width="50%">Subject: <%=getID.getSubject(rs.getInt("categories")).getStrsubjectname() %></td>
						<td width="50%">Edition: <%=getID.getEditionById(rs.getInt("edition")).getEditionname() %></td>
					</tr>
					<tr>
						<td>Condition: <%=getID.getConditionById(rs.getInt("bookcondition")).getStrconditionname() %></td>
						<td>Seller: <%= getID.getUser(rs.getInt("userid")).getFname()%> <%= getID.getUser(rs.getInt("userid")).getLname()%> </td>
					</tr>
					<tr>
						<td>Listed On: <%=sdf.format(rs.getTimestamp("listdate")) %> </td>
						<td>Notes: <%=rs.getString("note").length()>100?rs.getString("note").substring(0,98).replaceAll("<p>","")+"...":rs.getString("note") %></td>
					</tr>
					<tr>
					<td>You Save: <%=100-((rs.getDouble("offerprice")/rs.getDouble("retailprice")))*100 +"%" %> </td>
					<td><a href="ShowContact.jsp?userid=<%=rs.getInt("userid") %>&bookid=<%=rs.getInt("transbookid") %>"  class="fancybox fancybox.iframe">Contact</a></td>
					</tr>
				</table>
			</td>
			
		</tr>
		<tr>
			<td colspan="3"> <hr /></td>
		</tr>
		<%} %>
		
		
		
		</table>
		</div>		
		</div>
		<div id="text">
			
			
			
			
		</div>
		
		
		

		
</body>
</html>
<jsp:include page="footer.jsp"></jsp:include>